<template>
	<view>
		<view style="display: flex;flex-direction: column;align-items: center;">
			<image style="width: 180upx;height: 180upx;margin-top: 120upx;" src="../../static/images/wk-logo.png" mode=""></image>

			<view style="display: flex;flex-direction: row;align-items: center;margin-top: 100upx;"  @click="selectImg">
				<image style="width: 24upx;height: 24upx;" :src="selectSrc" mode="" ></image>
				<view style="margin-left: 16upx;color: #A6A6A6;font-size: 24upx;">已阅读并同意
					<span style="font-size: 24upx;color: #FF4E4C;" @click="toUserAgreement"> 《威客字节用户协议》
					</span>
					<span style="font-size: 24upx;color: #FF4E4C;" @click="toPriacy"> 《隐私政策》
					</span>
				</view>

			</view>
			<button style="height: 80upx;width: 628upx;background: #06C25F;color: #FFFFFF;margin-top: 20upx;
			text-align: center;line-height: 80upx;border-radius: 40upx;"
			 @getphonenumber="getPhoneNumber" open-type="getPhoneNumber">微信手机号一键登录</button>
		</view>


	</view>
</template>

<script>
	import {
		login_mobile
	} from '../../api/mine/auth.js'

	import {
		set
	} from '../../utils/local.js'
	export default {
		data() {
			return {
				userInfo: {},
				selectSrc: "../../static/images/login-no-select.png",
				selectStatus: false,
				code: ''
			}
		},
		// 加载登录凭证
		onLoad: function(options) {
			let that = this;
			uni.login({
				provider: 'weixin',
				success: res => {
					that.code = res.code
					console.log(that.code)
				}
			})
		},

		methods: {
			toUserAgreement() {
				uni.navigateTo({
					url: '../user-agreement/user-agreement'
				})
			},
			toPriacy(){
				uni.navigateTo({
					url:'../privacy-policies/privacy-policies'
				})
			},
			getPhoneNumber(e) {
				let that = this;
				if (!this.selectStatus) {
					uni.showToast({
						icon: 'none',
						title: "请勾选用户协议"
					})
					return
				}
				console.log(e)
				// 不允许授权
				if (e.detail.errMsg !== "getPhoneNumber:ok") {
					return;
				}
				let encryptedData = e.detail.encryptedData
				let iv = e.detail.iv
				uni.checkSession({
					success: (res) => {
						let params = {}
						params.code = that.code;
						let wxLoginEncodeRequest = {}
						wxLoginEncodeRequest.encryptedData = encryptedData
						wxLoginEncodeRequest.iv = iv
						params.wxLoginEncodeRequest = wxLoginEncodeRequest
						login_mobile(params).then(res => {
							if (res.status === 200) {

								uni.switchTab({
									url: '../mine/mine'
								})
							}

						})
					}
				})
			},
			selectImg() {
				if (!this.selectStatus) {
					this.selectSrc = "../../static/images/login-select-icon.png"
					this.selectStatus = true
				} else {
					this.selectSrc = "../../static/images/login-no-select.png"
					this.selectStatus = false
				}
			}
		}
	}
</script>

<style>

</style>
